package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.*;

import java.util.HashMap;
import java.util.Map;

//区域对象
@Setter@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Region extends BaseDomain {
    public static final Integer STATE_NOMAL = 0; //普通
    public static final Integer STATE_COMMEND = 1; //推荐

    private String name; //区域名称

    private Integer state = STATE_NOMAL; //状态

    private Region parent; //父区域

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("state", state);
        if (parent != null) {
            map.put("parentId", parent.getId());
            map.put("parentName", parent.getName());
        }
        return JSONUtil.toJSONString(map);
    }

    //{id:xx,text:xx,tags:["xx"]}
    public Map<String, Object> toTreeview() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("text", name);
        map.put("lazyLoad", true);//treeview启动懒加载
        if (state == STATE_COMMEND) {
            map.put("tags", new String[] {"推荐"});
        }
        return map;
    }
}